package com.zhengshang.web.controller.app;

import com.zhengshang.api.domain.AppGame;
import com.zhengshang.api.service.IAppGameService;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.core.domain.entity.SysRole;
import com.zhengshang.common.core.page.TableDataInfo;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.common.utils.SecurityUtils;
import com.zhengshang.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游戏Controller
 * 
 * @author zyf
 * @date 2021-06-01
 */
@RestController
@RequestMapping("/app/game")
public class AppGameController extends BaseController
{
    @Autowired
    private IAppGameService appGameService;

    /**
     * 查询游戏列表
     */
    @PreAuthorize("@ss.hasPermi('app:game:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppGame AppGame)
    {
        startPage();
        List<AppGame> list = appGameService.selectAppGameList(AppGame);
        return getDataTable(list);
    }

    /**
     * 导出游戏列表
     */
    @PreAuthorize("@ss.hasPermi('app:game:export')")
    @Log(title = "游戏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppGame AppGame)
    {
        List<AppGame> list = appGameService.selectAppGameList(AppGame);
        ExcelUtil<AppGame> util = new ExcelUtil<AppGame>(AppGame.class);
        return util.exportExcel(list, "game");
    }

    /**
     * 获取游戏详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:game:query')")
    @GetMapping(value = "/{gameId}")
    public AjaxResult getInfo(@PathVariable("gameId") Long gameId)
    {
        return AjaxResult.success(appGameService.selectAppGameById(gameId));
    }

    /**
     * 新增游戏
     */
    @PreAuthorize("@ss.hasPermi('app:game:add')")
    @Log(title = "游戏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGame AppGame)
    {
        AppGame.setCreateBy(SecurityUtils.getUsername());
        return toAjax(appGameService.insertAppGame(AppGame));
    }

    /**
     * 状态修改
     */
    @PutMapping("/changeState")
    public AjaxResult changeStatus(@RequestBody AppGame appGame)
    {
        return toAjax(appGameService.updateGameState(appGame));
    }

    /**
     * 修改游戏
     */
    @PreAuthorize("@ss.hasPermi('app:game:edit')")
    @Log(title = "游戏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGame AppGame)
    {
        AppGame.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(appGameService.updateAppGame(AppGame));
    }

    /**
     * 删除游戏
     */
    @PreAuthorize("@ss.hasPermi('app:game:remove')")
    @Log(title = "游戏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gameIds}")
    public AjaxResult remove(@PathVariable Long[] gameIds)
    {
        return toAjax(appGameService.deleteAppGameByIds(gameIds));
    }
}
